package com.isoftstone.app.controller.mine;

import com.isoftstone.bank.controller.base.BaseController;
import com.isoftstone.common.Tidings;
import com.isoftstone.common.base.SessionManager;
import com.isoftstone.util.Const;
import com.isoftstone.util.PageData;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author: zhaojg
 * @Description
 * @Date: Created in 17:42 2017/12/19
 * @Modified by:
 */
@Controller
public class MineController extends BaseController{

    /**
     * 退出
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/app/admin/logout")
    @ResponseBody
    public Object logout(HttpServletRequest request, HttpServletResponse response) {
        Tidings<Object> tidings = new Tidings<Object>();
        ModelAndView mv = this.getModelAndView();
        PageData pd = this.getPageData();
        try{
            Session session = SessionManager.getSession();    //以下清除session缓存
            session.removeAttribute("accessToken");
            session.removeAttribute("userid");
            //shiro销毁登录
            Subject subject = SecurityUtils.getSubject();
            subject.logout();
            tidings.setMsg("成功");
            tidings.setStatus(Const.SUCCESS);
        }catch (Exception e){
            tidings.setMsg("失败");
            tidings.setStatus(Const.ERROR);
            e.printStackTrace();
        }
        return tidings;
    }
}
